package com.wnx.job.modules.nms.controller;

import com.wnx.job.common.api.Const;
import com.wnx.job.common.api.ResultData;
import com.wnx.job.common.mapstruct.ChannelMapper;
import com.wnx.job.modules.nms.dto.ChannelParam;
import com.wnx.job.modules.nms.model.NmsChannel;
import com.wnx.job.modules.nms.service.NmsChannelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wangnaixing
 * @since 2021-12-16
 */
@Slf4j
@RestController
@RequestMapping("/nms/nmsChannel")
@Api(tags = "ChannelController",description = "咨询栏目管理")
public class NmsChannelController {
    @Resource
    private NmsChannelService channelService;


    /**
     * 增加咨询栏目
     * @param channelParam
     * @return
     */
    @PostMapping("/save")
    @ApiOperation("增加咨询栏目")
    public ResultData<String> save(@RequestBody @Validated ChannelParam channelParam){
        log.info("【=======系统正在增加咨询栏目中，该咨询栏目的信息为：============】");
        NmsChannel channel = ChannelMapper.INSTANCE.toPojo(channelParam);
        channel.setCreated(new Date());
        channelService.save(channel);
        log.info("【==========系统新增咨询栏目成功！=============】");
        return ResultData.success(Const.ADD_CHANNEL_SUCCESS);
    }


    /**
     *根据ID删除咨询栏目
     * @param id
     * @return
     */
    @GetMapping("/delete/{id}")
    @ApiOperation("根据ID删除咨询栏目")
    public ResultData<String> delete(@PathVariable(name = "id")Long id){
        log.info("【=========系统正在删除咨询栏目，删除咨询栏目ID为：{}=======】",id);
        channelService.deleteChannel(id);
        log.info("【============系统删除咨询栏目成功！！===========】");
        return ResultData.success(Const.DELETE_CHANNEL_SUCCESS);
    }

    /**
     * 修改咨询栏目
     * @param channelParam
     * @return
     */
    @PostMapping("/update/{id}")
    @ApiOperation("修改咨询栏目")
    public ResultData<String> update(@RequestBody @Validated ChannelParam channelParam,@PathVariable("id") Long id){
        log.info("【=======系统正在修改咨询栏目中，该公司的信息为：============】");
        NmsChannel channel = ChannelMapper.INSTANCE.toPojo(channelParam);
        channel.setUpdated(new Date());
        channelService.updateById(channel);
        log.info("【============系统修改咨询栏目成功！！===========】");
        return ResultData.success(Const.UPDATE_CHANNEL_SUCCESS);
    }

    /**
     * 根据ID获取咨询信息
     * @param id
     * @return
     */
    @GetMapping("/findById/{id}")
    @ApiOperation("根据ID获取咨询信息")
    public ResultData<NmsChannel> findById(@PathVariable(name = "id")Long id){
        log.info("【=======系统正在根据ID查询咨询栏目中============】");
        NmsChannel channel =  channelService.getById(id);
        log.info("【=======系统正在根据ID查询咨询栏目成功,该咨询栏目的信息为：{}============】",channel);
        return ResultData.success(Const.QUERY_CHANNEL_SUCCESS,channel);
    }

    /**
     * 获取咨询栏目树
     * @return
     */
    @GetMapping("/getChannelTree")
    @ApiOperation("获取咨询栏目树")
    public ResultData<List<ChannelParam>> getChannelTree(){
        log.info("==========系统正在获取咨询栏目树==========");
        List<ChannelParam> channelList =  channelService.getChannelTree();
        log.info("==========系统成功获取到咨询栏目树==========");
        return ResultData.success(Const.QUERY_CHANNEL_TREE_SUCCESS,channelList);
    }

    /**
     * 查询全部咨询栏目
     * @return
     */
    @GetMapping("/findAll")
    @ApiOperation("查询全部咨询栏目")
    public ResultData<List<NmsChannel>> findAll(){
        return ResultData.success(Const.QUERY_CHANNEL_SUCCESS,channelService.list());
    }



    /**
     * 根据栏目位置获取咨询栏目树
     * @return
     */
    @GetMapping("/getChannelTreeByPosition")
    @ApiOperation("根据栏目位置获取咨询栏目树")
    public ResultData<List<ChannelParam>> getChannelTreeByPosition(){
        log.info("================（网站前台）系统正在获取获取咨询分类树中==========");
        List<ChannelParam>   channelList = channelService.findChannelTreeByPosition(Const.Channel_NAV);
        log.info("=======（网站前台）系统正在成功获取咨询分类树==========");
        return ResultData.success(Const.QUERY_CHANNEL_TREE_SUCCESS,channelList);
    }


    /**
     * 根据咨询栏目ID获取栏目分类信息
     * @param id
     * @return
     */
    @GetMapping("/channel/finById/{id}")
    @ApiOperation("根据咨询栏目ID获取栏目分类信息")
    public ResultData<NmsChannel> findChannelById(@PathVariable(name = "id")Long id){
        log.info("=============（网站前台）系统根据正在栏目ID获取栏目信息中。。。============");
        NmsChannel channel =  channelService.getById(id);
        log.info("==============（网站前台）系统成功根据正在栏目ID获取栏目信息！！！=============");
        return ResultData.success(Const.QUERY_CHANNEL_SUCCESS,channel);
    }




}

